#ifndef CATEGORYVIEW_H
#define CATEGORYVIEW_H

#include <gtkmm.h>
#include "documents.h"
#include "docview.h"
#include "filterview.h"

class FilterView;
class DocView;
class CategoryView : public Gtk::TreeView
{
	public:
	CategoryView();
	virtual ~CategoryView();
	void set_documents(sdms::documents*);
	void update();
	void set_docview(DocView*);
	void set_filterview(FilterView*);
	
	private:
	// Override Signal handler:
	// Alternatively, use signal_button_press_event().connect_notify()
  virtual bool on_button_press_event(GdkEventButton *ev);

	//Signal handler for popup menu items:
	virtual void on_menu_file_popup_generic();
	virtual void insert_category();
	virtual void edit_category();
	virtual void remove_category();
	virtual void remove_all_category();
	virtual void category_movemode();
	virtual void select_category(const Gtk::TreeStore::Path& path, Gtk::TreeViewColumn* column);
	virtual void datarender(Gtk::CellRenderer* , const Gtk::TreeModel::iterator& );
	virtual void save_category(const Glib::ustring& path_string, const Glib::ustring& new_text);
	virtual void drag_end(const Glib::RefPtr<Gdk::DragContext>& context);
	virtual void drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time);
	virtual void drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,   Gtk::SelectionData& selection_data, guint, guint);

	void getrow(Gtk::TreeModel::Children c,std::string pname, Gtk::TreeModel::Row& row);
	void sync(Gtk::TreeModel::Children child);

  //Tree model columns:
  class ModelColumns : public Gtk::TreeModel::ColumnRecord
  {
  public:

    ModelColumns()
    { add(name);add(count);}

 	//Gtk::TreeModelColumn<unsigned int> id;
	//Gtk::TreeModelColumn<unsigned int> parent_id;
	//Gtk::TreeModelColumn<unsigned int> sequence;
	Gtk::TreeModelColumn<unsigned int> count;
	Gtk::TreeModelColumn<Glib::ustring> name;
    //Gtk::TreeModelColumn<Glib::ustring> comment; 
  };
  
  ModelColumns columns;

  //The Tree model:
  Glib::RefPtr<Gtk::TreeStore> refTreeModel;

	Gtk::Menu menuPopup;
	Gtk::CheckMenuItem menuCategoryMoveMode;
	Gtk::TreeView::Column categorycolumn;
	Gtk::CellRendererText cellrenderer;
	std::vector<Gtk::TargetEntry> categorytarget;
	
	bool editstatus;
	sdms::documents* mydoc;
	sigc::connection c1,c2;
	DocView* docview;
	FilterView* filterview;
};

#endif 
